package cn.edu.nyist.integration.service.impl;

import cn.edu.nyist.integration.common.ServerResponse;
import cn.edu.nyist.integration.entity.Category;
import cn.edu.nyist.integration.mapper.CategoryMapper;
import cn.edu.nyist.integration.service.CategoryService;
import cn.edu.nyist.integration.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public ServerResponse addCategory(Category category){
        //增加的时候也要请缓存
        redisUtil.del("categoryList");

        category.setCreateTime(new Date());
        category.setUpdateTime(new Date());
        System.out.println("service category = "+category);
        int row = categoryMapper.insert(category);
        if (row == 0){
            return ServerResponse.createByErrorMessage("添加分类失败");
        }

        return ServerResponse.createBySuccess();
    }

}
